package cuit.campus.taskRunning.user.handler;

import cuit.campus.taskRunning.user.enums.TaskTypeEnum;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class TaskTypeEnumTypeHandler extends BaseTypeHandler<TaskTypeEnum> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, TaskTypeEnum parameter, JdbcType jdbcType) throws SQLException {
        ps.setInt(i,parameter.getNum());
    }

    @Override
    public TaskTypeEnum getNullableResult(ResultSet rs, String columnName) throws SQLException {
        Integer num = rs.getInt(columnName);
        return TaskTypeEnum.getByNum(num);
    }

    @Override
    public TaskTypeEnum getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        Integer num = rs.getInt(columnIndex);
        return TaskTypeEnum.getByNum(num);
    }

    @Override
    public TaskTypeEnum getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        Integer num = cs.getInt(columnIndex);
        return TaskTypeEnum.getByNum(num);
    }
}
